import React, {Component} from 'react';
import {Popup, Tab,Button,Group,Field ,NumberPicker,SelectField, TextField,NoticeBar,CheckboxField,Toast  } from 'saltui';
import Number from  '../../room/Number'
import InputText from '../diy/InputText'
import InputChecked from '../diy/InputChecked'
import  Ajax  from '../../../../Common/Ajax';
import InputSelected from '../diy/InputSelected'


/**
 *
 */
export default class RoomEdit extends React.Component {
  constructor(props) {


    super(props);
    console.info(this.props);
    this.state = {
      prices :[],
      data:{
        id:this.props.id,
        floor:this.props.floor,
        name: this.props.room_name,
        price: this.props.price,
        roomtype:this.props.roomtype,
        roomstatus:this.props.roomstatus,
      },
      post:{
        id:this.props.id
      }

    };
    this.state.buttonName = this.props.buttonName;


  }

  handleTextChange = (value) =>{
    let data = this.state.post;
    data.name = value;
    this.setState({post:data});
  }

  handleSave = () =>{
    Toast.show({
      type: 'loading',
      content: '保存中...',
      autoHide:false
    });

    setTimeout(() => {
      Ajax.post("room/update",this.state.post);
      Toast.hide(() => {
      });

      Toast.show({
        type: 'loading',
        content: '保存成功',
      });

      Popup.hide();
      this.props.onChange(this.props.typeid);
    }, 2000);
  }


  handleOption= (key,value) =>{
    let data = this.state.post;
    data[key] = value;
    this.setState({post:data});
  }


  render() {
    let that = this;
    return <div className="demo-popup-container">     <Group.List >

      <Field label="楼层" tip={<div>客房所属楼层</div>}>
        <div>
          {this.props.floor_name}
        </div>
      </Field>


      <Field label="客房名字" tip={<div>输入客房名字</div>}>
        <div>
          <InputText value={this.state.data.name} onChange={this.handleTextChange}  />
        </div>
      </Field>

      <Field label="价格" tip={<div>请输入此客房类型统一价格</div>}>
        <div>
          <Number value={this.state.data.price} id = 'price' onChange={that.handleOption} />
        </div>
      </Field>


      <Field label="客房类型" tip={<div>输入类型名字</div>}>
        <div>
          <InputSelected option={this.props.option.roomtype}  id="roomtype" onChange={this.handleOption} value={this.state.data.roomtype} />
        </div>
      </Field>


      <Field label="状态" tip={<div>输入状态</div>}>
        <div>
          <InputSelected option={this.props.option.roomstatus } id="roomstatus" onChange={this.handleOption} value={this.state.data.roomstatus} />
        </div>
      </Field>





    </Group.List>

      <div className="notice-div">
        <NoticeBar className="noticeMessage" message={"客房管理"} closable={false} type="warning" />
      </div>
      <div className="demo-line">
        <Button type="secondary"  size="small" onClick={this.handleSave} >提交</Button>
        <Button type="secondary"  size="small" onClick={Popup.hide} >取消</Button>
      </div></div>
  }
}
